﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace TimKen.Web.Admin.Inbox
{
    public partial class InboxSend_List : TimKen.App.AdminPage
    {
        TimKen.BussLogic.InboxManager inboxM = new TimKen.BussLogic.InboxManager();

        public override string ActionCode
        {
            get
            {
                return "95";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            BindData();
        }

        protected void BindData()
        {
            DataSet ds = inboxM.GetList(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, "", CurrentUserName, -1);
            AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[1].Rows[0]["total"]);

            this.grdInbox.DataSource = ds.Tables[0].DefaultView;
            this.grdInbox.DataBind();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }

        protected void grdInbox_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "DeleteMessage")
            {
                int msgID = int.Parse(e.CommandArgument.ToString());
                TimKen.DataEntity.Inbox inbox = inboxM.GetModel(msgID);
                inboxM.Delete(inbox.MsgNo, 1);
                BindData();
            }
        }

        protected string GetToID(object ToID, object ToAll)
        {
            if (ToAll.ToString() == "1")
                return GetLangString("MessageToAll");
            else if (ToAll.ToString() == "2")
                return GetLangString("MessageSendToMany");
            else
                return ToID.ToString();
        }
    }
}
